import 'package:flutter/material.dart';
import 'package:whale/helper/utils/popup/index.dart';

import '../../helper/utils/util.dart';
import 'index.dart';
import 'widgets/widgets.dart';

class PopupDemoPage extends GetView<PopupDemoController> {
  const PopupDemoPage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    final state = controller.state;
    return ListView(
      children: [
        ListTile(
          title: Text('alert'),
          onTap: () async {
            var action = await Popup.alert(title: '温馨提示', msg: '您是否要开启动画');
            if (action) {
              Popup.alert(title: '温馨提示', msg: '开启动画成功');
            }
          },
        ),
        ListTile(
          title: Text('bottom_list'),
          trailing: Text(state.text1 ?? ''),
          onTap: () async {
            await Popup.bottomSheet(
                data: List.generate(3, (index) => '$index'),
                initIndex: 3,
                onTap: (p0) {
                  state.text1 = '$p0';
                  controller.update();
                });
          },
        ),
        ListTile(
          title: Text('bottom_list_radio'),
          trailing: Text(state.text2 ?? ''),
          onTap: () async {
            await Popup.bottomRadioSheet(
                data: List.generate(100, (index) => '$index'),
                initIndexs: controller.state.radioList,
                title: '选择',
                onSure: (p0) {
                  controller.state.radioList = p0;
                  state.text2 = '${p0.first}';
                  controller.update();
                });
          },
        ),
        ListTile(
          title: Text(
            'drop_down',
            key: controller.state.dpKey,
          ),
          trailing: Text(state.text3 ?? ''),
          onTap: () async {
            final p0 = await Popup.dropDown(
              sourceKey: controller.state.dpKey,
              data: List.generate(100, (index) => '$index'),
              initValue: '5',
            );
            state.text3 = p0.toString();
            controller.update();
          },
        ),
        ListTile(
          title: Text('wheel'),
          trailing: Text(state.text4 ?? ''),
          onTap: () async {
            await Popup.bottomWheel(
                data: List.generate(100, (index) => '$index'),
                initIndex: 3,
                onSure: (value) {
                  Get.log('$value');
                  Get.back();
                  state.text4 = '$value';
                  controller.update();
                },
                onChange: (p0) {
                  Get.log('$p0');
                });
          },
        ),
        ListTile(
          title: Text(
            'notice',
          ),
          trailing: Text(state.text5 ?? ''),
          onTap: () async {
            Popup.notice(
              child: NoticeView(),
            );
            // await Future.delayed(Duration(seconds: 1));
            // Popup.notice(
            //     title: '我是一条通知22',
            //     msg: '我是通知内容22',
            //     action: Container(
            //       width: 50.r,
            //       height: 32.r,
            //       alignment: Alignment.center,
            //       decoration: BoxDecoration(
            //           color: Colors.amber,
            //           borderRadius: BorderRadius.circular(10.r)),
            //       child: Text(
            //         '发消息',
            //         style: TextStyle(color: Colors.white, fontSize: 10.sp),
            //       ),
            //     ));
          },
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<PopupDemoController>(
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text("popup_demo")),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
